#include "madc.h"
#include "stdio.h"

uint32_t madc_get_data(uint32_t *adc)
{
	return bsp_adc_get_data(adc);
}

uint8_t light_smoke_get_data(int *light,int *smoke)
{
	uint32_t adc[3] = {0};
	
	if (madc_get_data(adc) != 1)
	{
		*light = light_get_data(adc[0]);
		*smoke = smoke_get_data(adc[1]);
	}else{
		return 1;
	}
	
	return 0;
}
float Vrl;
int smoke_get_data(uint32_t smoke_adc)
{
	Vrl = adc_ref_voltage * smoke_adc *100 / (float)adc_ref_value;
  return  (uint16_t)(Vrl);
}

int light_get_data(uint32_t light_adc)
{
	if (light_adc > 4000)
	{
		light_adc = 4000;
	}
	else if (light_adc < 10)
	{
		light_adc = 0;
	}
	
	float data = light_adc*100 / 4000.0f;
	
	return (uint8_t)(100 - data);
}



